package com.uvlab.sitespot.io;


import com.uvlab.sitespot.service.JxAppService;
import com.uvlab.sitespot.service.member.JxMember;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

@CrossOrigin
@RestController
@RequestMapping(value = "/rest/member")
public class JxMemberController {

    @Resource(name = "svc")
    private JxAppService svc;

    @RequestMapping(method = RequestMethod.GET)
    public HashMap getMembers(@RequestParam(value = "name" ,required = false) String name,
                              @RequestParam(value = "tel",required = false)String tel){
        HashMap<String,String> params=new HashMap<>();
        params.put("name",name);
        params.put("tel",tel);
        return svc.getMemberService().getMemberList(params);
    }

    @RequestMapping(method = RequestMethod.POST)
    public void addMembers(@RequestBody JxMember mem){
        svc.getMemberService().addMember(mem);
    }


    @RequestMapping(method = RequestMethod.PUT)
    public void updateMembers(@RequestBody JxMember mem){
        //  svc.getMemberService().updateMember("username", "zyr", "jys");
        svc.getMemberService().updateMember(mem);
    }

    @RequestMapping(method = RequestMethod.DELETE,value ="/{id}")
    public void deleteMembers(@PathVariable(value = "id")String id){
        svc.getMemberService().deleteMember(id);
    }

    @RequestMapping(method = RequestMethod.GET,value ="/{id}")
    public JxMember getById(@PathVariable(value = "id")String id){
        return svc.getMemberService().getById(id);
    }

}
